package cn.dujc.superkid.adapter;
import android.content.Intent;
import android.support.annotation.Nullable;
import android.view.View;
import android.webkit.WebView;
import android.widget.TextView;
import java.util.ArrayList;
import java.util.List;
import cn.dujc.core.adapter.BaseQuickAdapter;
import cn.dujc.core.adapter.BaseViewHolder;
import cn.dujc.superkid.R;
import cn.dujc.superkid.activities.ErrorContinueActivity;
import cn.dujc.superkid.activities.ResolvtionActivity;
import cn.dujc.superkid.bean.WrongQuestionResult;

public class ErrorQueAdapter extends BaseQuickAdapter<WrongQuestionResult.ListBean, ErrorQueAdapter.MyViewHolder> {
   String action;
   private OnItemClickListener onItemClickListener;
   public void setOnItemClickListeners(OnItemClickListener onItemClickListener){
       this.onItemClickListener=onItemClickListener;
   }

    public ErrorQueAdapter(int layoutResId, @Nullable List<WrongQuestionResult.ListBean> data) {
        super(layoutResId, data);
    }

     public void setAction(String action){
        this.action=action;
     }
    @Override
    public MyViewHolder createBaseViewHolder(View view) {
        return new MyViewHolder(view);
    }

    @Override
    protected void convert(final MyViewHolder helper, final WrongQuestionResult.ListBean item) {
        helper.addOnClickListener(R.id.error_add);
        helper.title.loadData(item.getQuestion_title(),"text/html; charset=UTF-8", null);
        helper.setText(R.id.correct_answer, "错误答案：" + item.getWrong().get(0));
        helper.getView(R.id.error_add).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onItemClickListener.onItemClick(item);
            }
        });
        helper.continu.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent(mContext, ErrorContinueActivity.class);
                intent.putExtra("type", item.getQuestion_type());
                intent.putExtra("title", item.getQuestion_title());
                intent.putExtra("good_key", item.getWrong_key());
                intent.putExtra("action",action);
                List<String> answers = item.getExercises_answer();
                intent.putStringArrayListExtra("answer", (ArrayList<String>) answers);
                mContext.startActivity(intent);
            }
        });
        helper.resolvtion.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent1=new Intent(mContext,ResolvtionActivity.class);
                intent1.putExtra("title",item.getQuestion_title());
                intent1.putExtra("jiexi",item.getExplain_ex());
                intent1.putExtra("daan",item.getCorrect_answer().get(0));
                mContext.startActivity(intent1);
            }
        });
    }

    static class MyViewHolder extends BaseViewHolder {
        private View mView;
        TextView resolvtion;
        TextView continu;
        WebView title;
        public MyViewHolder(View itemView) {
            super(itemView);
            mView = itemView;
            resolvtion = itemView.findViewById(R.id.error_resolvtion);
            continu = itemView.findViewById(R.id.error_continu);
            title=itemView.findViewById(R.id.good_que_title);
        }
    }
    public interface OnItemClickListener{
         void onItemClick(WrongQuestionResult.ListBean item);
    }
}